package com.wulijie.command;

/**
 * @Author cui
 * @Data
 */
public class RemoteHandle {
    private Command[] onCommands;
    private Command[] offCommands;

    private Command undoCommand;

    public RemoteHandle() {
        onCommands = new Command[5];
        offCommands = new Command[5];

        for (int i = 0; i < 5; i++) {
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    public void setCommand(int no, Command onCommand, Command offCommand){
        onCommands[no] = onCommand;
        offCommands[no] = offCommand;
    }

    public void buttonOnPush(int no){
        Command command = onCommands[no];
        if (null != command) {
            command.execute();
            undoCommand = command;
        }
    }

    public void buttonOffPush(int no){
        Command command = offCommands[no];
        if (null != command) {
            command.execute();
            undoCommand = command;
        }
    }

    public void undo(){
        this.undoCommand.undo();
    }

}
